﻿function BindCheckBoxEvent(obj) {
    $("#cb_All,#cb_All2").click(function() {
        var checked = $(this).attr("checked");
        $(":checkbox").not(",#cb_include").attr("checked", checked);
        if (obj) {
            setButton(obj, $("input:checked").not("#cb_All,#cb_All2,#cb_include").length > 0);
        }
    });
    $(":checkbox").not("#cb_All,#cb_All2,#cb_include").each(function() {
        BindCheckBox(obj, $(this));
    });

    var lenAll = $(":checkbox").not("#cb_All,#cb_All2,#cb_include").length;
    var lenChecked = $("input:checked").not("#cb_All,#cb_All2,#cb_include").length;

    $("#cb_All,#cb_All2").attr("checked", lenChecked == lenAll ? true : false);
}
function BindCheckBox(obj, _this) {
    _this.click(function() {
        var lenAll = $(":checkbox").not("#cb_All,#cb_All2,#cb_include").length;
        var lenChecked = $("input:checked").not("#cb_All,#cb_All2,#cb_include").length;
        if (obj) {
            setButton(obj, lenChecked > 0 ? true : false);
        }

        $("#cb_All,#cb_All2").attr("checked", lenChecked == lenAll ? true : false);
    });
}
function setButton(obj, val) {
    if (val) {
        obj.removeAttr("disabled");
    }
    else {
        obj.attr("disabled", "disabled");
    }
}
function BindSearchSwitch() {
    $(".searchPanel img").toggle(
        function() {
            $(this).attr("src", rootpath + "images/searchpanelplus.jpg");
            $(".searchPanel div").slideUp(500);
        },
        function() {
            $(this).attr("src", rootpath + "images/searchpanelminus.jpg");
            $(".searchPanel div").slideDown(500);
        }
    );

    hideSearchPanel();
}

function formReady() {
    //$(".dataform,.DG").show();
    $(window.parent.document).find("#ifr_main").height($(".adminMainContent").height() + 100);
}

function formloaded() {
    //$(".dataform,.DG,#dv_content").show();
    $("#dv_content").show();
    $(window.parent.document).find("#ifr_detail").height($(".adminMainContent").height() + 30);
}

function hideSearchPanel() {
    //$(".searchPanel div").slideUp(500);
}

function facebox(msg) {
    window.parent.facebox(msg);
}

function confirmbox(msg) {
    window.parent.confirmbox(msg);
}

function closebox() {
    window.parent.closebox();
}

function getCourseCover(filename) {
    if (filename == "") {
        filename = "default.jpg";
    }
    return rootpath + "data/coursepicture/" + filename;
}

function DrawImage(ImgD, iwidth, iheight) {
    var image = new Image();
    image.src = ImgD.src;
    if (image.width > 0 && image.height > 0) {
        if (image.width / image.height >= iwidth / iheight) {
            if (image.width > iwidth) {
                ImgD.width = iwidth;
            }
            else {
                ImgD.width = image.width; ImgD.height = image.height;
            }
        }
        else {
            if (image.height > iheight) {
                ImgD.height = iheight;
                ImgD.width = (image.width * iheight) / image.height;
            }
            else {
                ImgD.width = image.width; ImgD.height = image.height;
            }
        }
        $(ImgD).show();
    }
}

function openDialog(src, title, width, height) {
    window.parent.openDialog(src, title, width, height);
}
function closeDialog() {
    window.parent.closeDialog();
}